package kr.hkit.powerjava.chapter22.work;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Pro05 {
	private ArrayList<Double> arList;

	Scanner input;
	private double value = 0.0;
	private double result = 0.0;

	public Pro05(ArrayList<Double> arList) {
		this.arList = arList;
	}

	public double getNum() {
		input = new Scanner(System.in);
		value = input.nextDouble();
		return value;
	}

	public void addNum() {
		for (int i = 0; i < 10; i++) {
			System.out.print("점수를 입력하시오: ");
			getNum();
			if (!checkValue()) {
				arList.add(value);
			} else {
				System.out.println("재입력 바랍니다. 입력 값이 잘못 되었습니다.");
				i--;
			}
		}
	}

	public boolean checkValue() {
		if (value < 0 || value > 10) {
			return true;
		} else {
			return false;
		}
	}

	public double getTotal() {
		System.out.println("심사위원 점수 : " + arList);
		Collections.sort(arList);
		for (int i = 1; i < arList.size() - 1; i++) {
			result += arList.get(i);
		}

		return result;
	}

	public double getAvg() {
		return result / (arList.size() - 2);
	}

	@Override
	public String toString() {
		return String.format("점수 집계 [총점=%.2f, 평점=%.2f]", result, getAvg());
	}

}
